import { authService } from '@/services';

export default {
    namespace: 'auth',
    state: {
        baseInfo: {},
    },

    subscriptions: {
        // * 每个页面进来先执行这个。
        setup({ dispatch, history }) {
            console.log("login check............");
        }
    },

    effects: {
        * getBaseInfo({ payload }, { call, put, all, select }) {
            const data = {
                name: 1232333,
            }
            yield put({ type: 'getBaseInfoSuccess', payload: { data } });
            return data;
        },
        * getUserInfo({ payload }, { call, put, all, select }) {
            // const { token, ...data } = params || {};
            // const options = { method: 'get', data };
            // if (token) { // 可以使用传入的token覆盖localstroage中的token
            // options.token = token;
            // }
            // const nextapi = apiBuilder.create('user.GetMe', 'ME');
            // return nextAPI({
            //     data: [nextapi.api],
            //     token, // 可以使用传入的token覆盖localstroage中的token
            //     baseAPI: nextAPIURL, // 强制使用baseAPI，跳过配置;
            // });
            const { data } = yield call(authService.getUserInfo, payload);
            console.log(11111, data)
            return data;
        },
    },

    reducers: {
        getBaseInfoSuccess(state, { payload }) {
            console.log('success', payload)
            state.baseInfo = payload.data;
            return state.baseInfo
        },
    },
}